/**
 * 费用(物业)
 * @author truexin
 * @date   2016/07/07
 */
import MenuBtn from '../components/MenuBtn.js';

(function (lf, r) {
    
    let RC = r.createClass,
        ajax = lf.utils.ajax;
    let count = 2,
        menuList = [
            {
                url: "property-fee-query.html",
                text: '费用查询',
                tip: '',
            },
            {
                url: "property-meter-reading.html",
                text: '仪表读数',
                // tip: '已抄',
            }
        
        ];
    
    let Body = RC({
        getInitialState() {
            return ({
                menuList: []
            })
        },
        componentWillMount() {
            let me = this,
                user = this.props.user;
            me.getHouseNum(user);
        },
        getHouseNum(user) {
            let me = this;
            ajax({
                type: 'get',
                data: {
                    houseId: user.houseId,
                },
                success: function (data) {
                    let houseNum = data.data.houseNum;
                    me.setCashList(user, houseNum);
                }
            }, lf.finger.api.household.getHouseInfo);

        },
        setCashList(user, houseNum) {
            let me = this;
            ajax({
                type: 'post',
                data: {
                    projectId: user.projectId,
                    houseNum: houseNum,
                },
                success: function (data) {
                    let tip = data.data && !data.data.notPayMoney ? '' : '未交';//未缴款金额合计
                    menuList[0].tip = tip;
                    me.setState({
                        menuList: menuList
                    });
                }
            }, lf.finger.api.fee.getTotalFee);
        },
        render: function () {
            return <div className="property-fee">
                <MenuBtn menuList={this.state.menuList} count={count}/>
            </div>
        }
    });
    lf.appJs.getUser(function (user) {
        r.render(<Body user={user}/>, document.getElementById('root'), function () {
            $('#root').css('background', '#f4f4f4');
            
        });
    });
    
    
})(liefeng, React)